/**
 * 2016，thor.com，all rights reserved。
 * 
 * Project：		palmmall-core
 * Filename：	AStoreQueryParamConverter.java
 * Created：		2016年9月5日
 * Creator：		wolv
 */
package com.thor.palmmall.rest.common;

import java.util.ArrayList;

import org.springframework.core.convert.converter.Converter;

import com.thor.commons.entity.KV;
import com.thor.commons.entity.UCN;
import com.thor.palmmall.spi.common.SContractQueryParam;

/**
 * @author wolv
 *
 */
public class SContractQueryParamConverter
    implements Converter<AContractQueryParam, SContractQueryParam> {

  public static SContractQueryParamConverter getInstance() {
    if (instance == null)
      instance = new SContractQueryParamConverter();
    return instance;
  }

  private static SContractQueryParamConverter instance;

  private SContractQueryParamConverter() {
  }

  @Override
  public SContractQueryParam convert(AContractQueryParam source) {
    if (source == null)
      return null;

    SContractQueryParam target = new SContractQueryParam();
    target.setPage(source.getPage());
    target.setPageSize(source.getPageSize());
    target.setStores(new ArrayList<String>());

    if (source.getStores() != null)
      target.getStores().addAll(source.getStores());
    target.setContracts(new ArrayList<UCN>());
    if (source.getContracts() != null)
      target.getContracts().addAll(source.getContracts());
    target.setUserGroups(new ArrayList<KV>());
    if (source.getUserGroups() != null)
      target.getUserGroups().addAll(source.getUserGroups());
    if (source.getOrder() != null) {
      target.setOrder(source.getOrder());
    }
    return target;
  }

}
